package com.hhhn.wk.main.tab2.view.xiangqing.fragment;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.TranslateAnimation;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import com.bigkoo.convenientbanner.ConvenientBanner;
import com.bigkoo.convenientbanner.holder.CBViewHolderCreator;
import com.gxz.PagerSlidingTabStrip;
import com.hhhn.wk.R;
import com.hhhn.wk.base.BaseFragment;
import com.hhhn.wk.config.Config;
import com.hhhn.wk.entity.User;
import com.hhhn.wk.main.tab1.host.Host;
import com.hhhn.wk.main.tab2.entity.Commodity;
import com.hhhn.wk.main.tab2.view.xiangqing.activity.CommodityXQActivity;
import com.hhhn.wk.main.tab2.view.xiangqing.adapter.ItemRecommendAdapter;
import com.hhhn.wk.main.tab2.view.xiangqing.adapter.NetworkImageHolderView;
import com.hhhn.wk.main.tab2.view.xiangqing.bean.Goods;
import com.hhhn.wk.main.tab2.view.xiangqing.bean.RecommendGoodsBean;
import com.hhhn.wk.main.tab2.view.xiangqing.widget.SlideDetailsLayout;
import com.hhhn.wk.main.tab3.activity.ConfirmOrderActivity;
import com.hhhn.wk.main.tab3.entity.ShoppingCartBean;
import com.hhhn.wk.pay.PayActivity;
import com.hhhn.wk.utils.AllPublic;
import com.hhhn.wk.utils.Constants;
import com.hhhn.wk.utils.SharePreferencesUser;
import com.hhhn.wk.widget.dialog.AddCartDialog;
import com.hhhn.wk.widget.dialog.PayDialog;
import org.json.JSONArray;
import org.json.JSONObject;
import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import static com.hhhn.wk.main.fragment.TabFragment02.Classify_allTypeFragment1.TAG;
import static com.hhhn.wk.utils.AllPublic.isHuoNiu;
/**
 * item页ViewPager里的商品Fragment
 */
public class GoodsInfoFragment extends BaseFragment implements View.OnClickListener, SlideDetailsLayout.OnSlideDetailsListener {
    private PagerSlidingTabStrip psts_tabs;
    private SlideDetailsLayout sv_switch;
    private ScrollView sv_goods_info;
    private FloatingActionButton fab_up_slide;
    public ConvenientBanner vp_item_goods_img, vp_recommend;
    private LinearLayout ll_goods_detail, ll_goods_config;
    private TextView tv_goods_detail, tv_goods_config;
    private View v_tab_cursor;
    public FrameLayout fl_content;
    public LinearLayout ll_current_goods, ll_activity, ll_comment, ll_recommend, ll_pull_up;
    public TextView tv_goods_title;//标题
    public TextView tv_new_price1;//一级价格
    public TextView tv_new_price2;//2级价格
    public TextView tv_new_price3;//3级价格
    public TextView tv_number1;//1级数量
    public TextView tv_number2;//1级数量
    public TextView tv_number3;//1级数量
    public TextView tv_old_price1;//原价
    public TextView tv_old_price2;//原价
    public TextView tv_old_price3;//原价
    public TextView tv_yunfei;//运费
    public TextView tv_shengyu;//剩余
    public TextView tv_address;//地址
    public TextView tv_xiaoliang;//销量
    /** 当前商品详情数据页的索引分别是图文详情、规格参数 */
    private int nowIndex;
    private float fromX;
    public GoodsConfigFragment goodsConfigFragment;
//    public GoodsCommentFragment goodsCommentFragment;
    public H5Fragment goodsInfoWebFragment;
    private Fragment nowFragment;
    private List<TextView> tabTextList;
    private List<Fragment> fragmentList = new ArrayList<>();
    private FragmentTransaction fragmentTransaction;
    private FragmentManager fragmentManager;
    public CommodityXQActivity activity;
    private LayoutInflater inflater;
    private TextView tv_pay;
    private String goods_id="";//商品id
    private Goods commodity=null;
    Handler handler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what){
                case 1:
                    setLoopView();
                    break;
            }
        }
    };
    private RelativeLayout mRelativeLayout;
    private TextView tv_add;//添加购物车
    private TextView tv_guige;//
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        activity = (CommodityXQActivity) context;
    }
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        savedInstanceState=getArguments();
         goods_id = savedInstanceState.getString("goods_id");
        Log.d("商品详情", "onCreateView: "+goods_id);
        return super.onCreateView(inflater, container, savedInstanceState);
    }
    @Override
    protected void initView(View mRootView) {
        tv_guige = findViewById(R.id.tv_guige);
        psts_tabs = findViewById(R.id.psts_tabs);
//      ll_empty_comment = findViewById(R.id.ll_empty_comment);
        fab_up_slide = findViewById(R.id.fab_up_slide);
        sv_switch = findViewById(R.id.sv_switch);
        sv_goods_info = findViewById(R.id.sv_goods_info);
        v_tab_cursor = findViewById(R.id.v_tab_cursor);
        vp_item_goods_img = findViewById(R.id.vp_item_goods_img);
        vp_recommend = findViewById(R.id.vp_recommend);
        fl_content = findViewById(R.id.fl_content);
        ll_current_goods =findViewById(R.id.ll_current_goods);
        ll_activity = findViewById(R.id.ll_activity);
        ll_comment = findViewById(R.id.ll_comment);
        ll_recommend = findViewById(R.id.ll_recommend);
        ll_pull_up = findViewById(R.id.ll_pull_up);
        ll_goods_detail = findViewById(R.id.ll_goods_detail);
        ll_goods_config = findViewById(R.id.ll_goods_config);
        tv_goods_detail = findViewById(R.id.tv_goods_detail);
        tv_goods_config = findViewById(R.id.tv_goods_config);
        tv_goods_title = findViewById(R.id.tv_goods_title);
        tv_new_price1 = findViewById(R.id.tv_new_price1);
        tv_new_price2 = findViewById(R.id.tv_new_price2);
        tv_new_price3 = findViewById(R.id.tv_new_price3);
        tv_number1 = findViewById(R.id.tv_number1);
        tv_number2 = findViewById(R.id.tv_number2);
        tv_number3 = findViewById(R.id.tv_number3);
        tv_old_price1 = findViewById(R.id.tv_old_price1);
        tv_old_price2 = findViewById(R.id.tv_old_price2);
        tv_old_price3 = findViewById(R.id.tv_old_price3);
        tv_yunfei = findViewById(R.id.tv_yunfei);
        tv_shengyu = findViewById(R.id.tv_shengyu);
        tv_address = findViewById(R.id.tv_address);
        tv_pay = findViewById(R.id.tv_pay);
        tv_add = findViewById(R.id.tv_add);
        tv_xiaoliang = findViewById(R.id.tv_xiaoliang);
        mRelativeLayout = findViewById(R.id.mRelativeLayout);
        WindowManager wm = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE);
        int width = wm.getDefaultDisplay().getWidth();
        int height = wm.getDefaultDisplay().getHeight();
        android.view.ViewGroup.LayoutParams pp =mRelativeLayout.getLayoutParams();
        pp.height =width;
        mRelativeLayout.setLayoutParams(pp);
        setDetailData();
//      setRecommendGoods();
        fab_up_slide.hide();
        //设置两个点图片作为翻页指示器，不设置则没有指示器，可以根据自己需求自行配合自己的指示器,不需要圆点指示器可用不设
        vp_item_goods_img.setPageIndicator(new int[]{R.mipmap.index_white, R.mipmap.index_red});
        vp_item_goods_img.setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.CENTER_HORIZONTAL);
        vp_recommend.setPageIndicator(new int[]{R.drawable.shape_item_index_white, R.drawable.shape_item_index_red});
        vp_recommend.setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.CENTER_HORIZONTAL);
    }
    // 开始自动翻页
    @Override
    public void onResume() {
        super.onResume();
        //开始自动翻页
        vp_item_goods_img.startTurning(4000);
    }
    // 停止自动翻页
    @Override
    public void onPause() {
        super.onPause();
        //停止翻页
        vp_item_goods_img.stopTurning();
    }
    protected void initData() {
        fragmentList = new ArrayList<>();
        tabTextList = new ArrayList<>();
        tabTextList.add(tv_goods_detail);
        tabTextList.add(tv_goods_config);
        getGoods();
    }
    @Override
    protected void initClick() {
//        ll_empty_comment.setOnClickListener(this);
        fab_up_slide.setOnClickListener(this);
        ll_current_goods.setOnClickListener(this);
        ll_activity.setOnClickListener(this);
        ll_comment.setOnClickListener(this);
        ll_pull_up.setOnClickListener(this);
        ll_goods_detail.setOnClickListener(this);
        ll_goods_config.setOnClickListener(this);
        sv_switch.setOnSlideDetailsListener(this);
        tv_pay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (AllPublic.isLogin(mActivity,mActivity)){
                    PayDialog.showSheet(mActivity,commodity.getPictureimage(),
                            commodity.getTitle(),
                            commodity.getWholesalePriceOne(),
                            commodity.getWholesalePriceTwo(),
                            commodity.getWholesalePriceThree(),
                            commodity.getWholesaleNumberOne(),
                            commodity.getWholesaleNumberTwo(),
                            commodity.getWholesaleNumberThree(),
                            new PayDialog.OnActionSheetSelected(){
                                @Override
                                public void onClick(int whichButton,int number,double zuizhongPrice,double zongji) {
                                    switch (whichButton){
                                        //购买
                                        case 0:
                                            //确定订单页面
                                            Intent intent=new Intent(mActivity, ConfirmOrderActivity.class);
                                            intent.putExtra("goods_id",goods_id);//商品ID
                                            intent.putExtra("commodityImg",commodity.getPictureimage());//图片
                                            intent.putExtra("commodityName",commodity.getTitle());//名称
                                            intent.putExtra("tmpFreight",commodity.getFreight());//运费
                                            //价格
                                            intent.putExtra("zuizhongPrice",zuizhongPrice+"");
                                            //数量
                                            intent.putExtra("number",number+"");
                                            //商品总计
                                            intent.putExtra("zongji",zongji+"");

                                            mActivity.startActivity(intent);
                                            break;
                                        //减
                                        case 1:
                                            break;
                                        //加
                                        case 2:
                                            break;
                                    }
                                }
                            },new DialogInterface.OnCancelListener() {
                                @Override
                                public void onCancel(DialogInterface dialogInterface) {
                                }
                            });
                }




            }
        });
        tv_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (AllPublic.isLogin(mActivity,mActivity)){
                    AddCartDialog.showSheet(mActivity,commodity.getPictureimage(),
                            commodity.getTitle(),
                            commodity.getWholesalePriceOne(),
                            commodity.getWholesalePriceTwo(),
                            commodity.getWholesalePriceThree(),

                            commodity.getWholesaleNumberOne(),
                            commodity.getWholesaleNumberTwo(),
                            commodity.getWholesaleNumberThree(),
                            new AddCartDialog.OnActionSheetSelected(){
                                @Override
                                public void onClick(int whichButton,int number) {
                                    switch (whichButton){
                                        //添加
                                        case 0:
                                            getADD(number);
                                            break;
                                        //减
                                        case 1:

                                            break;
                                        //加
                                        case 2:

                                            break;
                                    }
                                }
                            },new DialogInterface.OnCancelListener() {
                                @Override
                                public void onCancel(DialogInterface dialogInterface) {

                                }
                            });
                }



            }
        });
    }

    @Override
    protected int setLayoutResouceId() {
        return R.layout.fragment_goods_info;
    }

    /**
     * 加载完商品详情执行
     */
    public void setDetailData() {
        goodsConfigFragment = new GoodsConfigFragment();
//        goodsCommentFragment = new GoodsCommentFragment();
//        goodsInfoWebFragment = new GoodsInfoWebFragment();
        goodsInfoWebFragment = new H5Fragment();
        fragmentList.add(goodsConfigFragment);




        Bundle bundle = new Bundle();
        bundle.putString("goods_id",goods_id);
        goodsInfoWebFragment.setArguments(bundle);
        fragmentList.add(goodsInfoWebFragment);




        nowFragment = goodsInfoWebFragment;
        fragmentManager = getChildFragmentManager();
        //默认显示商品详情tab
        fragmentManager.beginTransaction().replace(R.id.fl_content, nowFragment).commitAllowingStateLoss();
    }

    /**
     * 设置推荐商品
     */
//    public void setRecommendGoods() {
//        List<RecommendGoodsBean> data = new ArrayList<>();
//        data.add(new RecommendGoodsBean("Letv/乐视 LETV体感-超级枪王 乐视TV超级电视产品玩具 体感游戏枪 电玩道具 黑色",
//                "http://img4.hqbcdn.com/product/79/f3/79f3ef1b0b2283def1f01e12f21606d4.jpg", new BigDecimal(599), "799"));
//        data.add(new RecommendGoodsBean("IPEGA/艾派格 幽灵之子 无线蓝牙游戏枪 游戏体感枪 苹果安卓智能游戏手柄 标配",
//                "http://img2.hqbcdn.com/product/00/76/0076cedb0a7d728ec1c8ec149cff0d16.jpg", new BigDecimal(299), "399"));
//        data.add(new RecommendGoodsBean("Letv/乐视 LETV体感-超级枪王 乐视TV超级电视产品玩具 体感游戏枪 电玩道具 黑色",
//                "http://img4.hqbcdn.com/product/79/f3/79f3ef1b0b2283def1f01e12f21606d4.jpg", new BigDecimal(599), "799"));
//        data.add(new RecommendGoodsBean("IPEGA/艾派格 幽灵之子 无线蓝牙游戏枪 游戏体感枪 苹果安卓智能游戏手柄 标配",
//                "http://img2.hqbcdn.com/product/00/76/0076cedb0a7d728ec1c8ec149cff0d16.jpg", new BigDecimal(299), "399"));
//        List<List<RecommendGoodsBean>> handledData = handleRecommendGoods(data);
//        //设置如果只有一组数据时不能滑动
//        vp_recommend.setManualPageable(handledData.size() == 1 ? false : true);
//        vp_recommend.setCanLoop(handledData.size() == 1 ? false : true);
//        vp_recommend.setPages(new CBViewHolderCreator() {
//            @Override
//            public Object createHolder() {
//                return new ItemRecommendAdapter();
//            }
//        }, handledData);
//    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_pull_up:
                //上拉查看图文详情
                sv_switch.smoothOpen(true);
                break;

            case R.id.fab_up_slide:
                //点击滑动到顶部
                sv_goods_info.smoothScrollTo(0, 0);
                sv_switch.smoothClose(true);
                break;

            case R.id.ll_goods_detail:
                //商品详情tab
                nowIndex = 0;
                scrollCursor();
                switchFragment(nowFragment, goodsInfoWebFragment);
                nowFragment = goodsInfoWebFragment;
                break;

            case R.id.ll_goods_config:
                //规格参数tab
                nowIndex = 1;
                scrollCursor();
                switchFragment(nowFragment, goodsConfigFragment);
                nowFragment = goodsConfigFragment;
                break;
            default:
                break;
        }
    }

    /**
     * 给商品轮播图设置图片路径
     */
    public void setLoopView() {
        List<String> imgUrls = new ArrayList<>();
        String[] strs=commodity.getImage().split(",");
        for(int i=0,len=strs.length;i<len;i++){
//            System.out.println(strs[i].toString());
            imgUrls.add(Constants.HTTPIMG+strs[i].toString());

        }
//
//        imgUrls.add("http://img4.hqbcdn.com/product/79/f3/79f3ef1b0b2283def1f01e12f21606d4.jpg");
//        imgUrls.add("http://img14.hqbcdn.com/product/77/6c/776c63e6098f05fdc5639adc96d8d6ea.jpg");
//        imgUrls.add("http://img13.hqbcdn.com/product/41/ca/41cad5139371e4eb1ce095e5f6224f4d.jpg");
//        imgUrls.add("http://img10.hqbcdn.com/product/fa/ab/faab98caca326949b87b770c8080e6cf.jpg");
//        imgUrls.add("http://img2.hqbcdn.com/product/6b/b8/6bb86086397a8cd0525c449f29abfaff.jpg");
        //初始化商品图片轮播
        vp_item_goods_img.setPages(new CBViewHolderCreator() {
            @Override
            public Object createHolder() {
                return new NetworkImageHolderView();
            }
        }, imgUrls);

        tv_goods_title.setText(commodity.getTitle());


        if (isHuoNiu(activity)){
            tv_new_price1.setText("￥"+commodity.getWholesalePriceOne());
            tv_new_price2.setText("￥"+commodity.getWholesalePriceTwo());
            tv_new_price3.setText("￥"+commodity.getWholesalePriceThree());
        }else {
            tv_new_price1.setText("￥?");
            tv_new_price2.setText("￥?");
            tv_new_price3.setText("￥?");
        }


        tv_number1.setText(commodity.getWholesaleNumberOne()+commodity.getProSpecifications());
        tv_number2.setText(commodity.getWholesaleNumberTwo()+commodity.getProSpecifications());
        tv_number3.setText(commodity.getWholesaleNumberThree()+commodity.getProSpecifications());



        if (isHuoNiu(activity)){
            tv_old_price1.setText(commodity.getOriginalPrice());
            tv_old_price2.setText(commodity.getOriginalPrice());
            tv_old_price3.setText(commodity.getOriginalPrice());
        }else {
            tv_old_price1.setText("?");
            tv_old_price2.setText("?");
            tv_old_price3.setText("?");
        }

        //设置文字中间一条横线
        tv_old_price1.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        tv_old_price2.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        tv_old_price3.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);

        tv_yunfei .setText("运费："+commodity.getFreight());
        tv_shengyu .setText("库存:"+commodity.getInventory());
        tv_address .setText("发货地："+commodity.getAddress());
        tv_xiaoliang .setText("销量："+commodity.getSales());
        tv_guige .setText("规格："+commodity.getGuige());

        mActivity.dismissLoad();
    }

    @Override
    public void onStatucChanged(SlideDetailsLayout.Status status) {
        if (status == SlideDetailsLayout.Status.OPEN) {
            //当前为图文详情页
            fab_up_slide.show();
            activity.vp_content.setNoScroll(true);
            activity.tv_title.setVisibility(View.VISIBLE);
            activity.psts_tabs.setVisibility(View.GONE);
        } else {
            //当前为商品详情页
            fab_up_slide.hide();
            activity.vp_content.setNoScroll(false);
            activity.tv_title.setVisibility(View.GONE);
            activity.psts_tabs.setVisibility(View.VISIBLE);
        }
    }
    /**
     * 滑动游标
     */
    private void scrollCursor() {
        TranslateAnimation anim = new TranslateAnimation(fromX, nowIndex * v_tab_cursor.getWidth(), 0, 0);
        anim.setFillAfter(true);//设置动画结束时停在动画结束的位置
        anim.setDuration(50);
        //保存动画结束时游标的位置,作为下次滑动的起点
        fromX = nowIndex * v_tab_cursor.getWidth();
        v_tab_cursor.startAnimation(anim);

        //设置Tab切换颜色
        for (int i = 0; i < tabTextList.size(); i++) {
            tabTextList.get(i).setTextColor(i == nowIndex ? getResources().getColor(R.color.text_red) : getResources().getColor(R.color.text_black));
        }
    }
    /**
     * 切换Fragment
     * <p>(hide、show、add)
     * @param fromFragment
     * @param toFragment
     */
    private void switchFragment(Fragment fromFragment, Fragment toFragment) {
        if (nowFragment != toFragment) {
            fragmentTransaction = fragmentManager.beginTransaction();
            if (!toFragment.isAdded()) {    // 先判断是否被add过
                fragmentTransaction.hide(fromFragment).add(R.id.fl_content, toFragment).commitAllowingStateLoss(); // 隐藏当前的fragment，add下一个到activity中
            } else {
                fragmentTransaction.hide(fromFragment).show(toFragment).commitAllowingStateLoss(); // 隐藏当前的fragment，显示下一个
            }
        }
    }
    /**
     * 处理推荐商品数据(每两个分为一组)
     *
     * @param data
     * @return
     */
    public static List<List<RecommendGoodsBean>> handleRecommendGoods(List<RecommendGoodsBean> data) {
        List<List<RecommendGoodsBean>> handleData = new ArrayList<>();
        int length = data.size() / 2;
        if (data.size() % 2 != 0) {
            length = data.size() / 2 + 1;
        }
        for (int i = 0; i < length; i++) {
            List<RecommendGoodsBean> recommendGoods = new ArrayList<>();
            for (int j = 0; j < (i * 2 + j == data.size() ? 1 : 2); j++) {
                recommendGoods.add(data.get(i * 2 + j));
            }
            handleData.add(recommendGoods);
        }
        return handleData;
    }
    //获取商品详情
    private void getGoods(){
        mActivity. showLoad();
        RequestParams params = AllPublic.getParamsProduct(mActivity, "/productInfo", false);
        params.addParameter("id",goods_id);
        User user = (User) SharePreferencesUser.getBean(mActivity, Constants.USER);
        if (user!=null){
            int isLogin = user.getIsLogin();
            if (isLogin==2){
                params.addParameter("merchantId",user.getUid());
            }else {

            }
        }else {

        }
        Log.d("获取商品详情", "getJSON: "+params);
        //请求
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override  //成功
            public void onSuccess(String result) {
                Log.d("获取商品详情：", result);
                try {
                    JSONObject jsonObject= new JSONObject(result);
                    String reason = jsonObject.getString("code");
                    if (reason.equals("0")) {
                        JSONArray records = jsonObject.getJSONArray("data");

//                        for (int i=0;i<records.length();i++){
                            commodity=new Goods();
                            JSONObject object = records.getJSONObject(0);
                            String picture = object.has("rotationChart") ? object.getString("rotationChart") : "";//产品图片
                            String pictureimage = object.has("productPicture") ? object.getString("productPicture") : "";//住产品图片
                            String wholesaleNumberOne = object.has("wholesaleNumberOne") ? object.getString("wholesaleNumberOne") : "";
                            String wholesaleNumberTwo = object.has("wholesaleNumberTwo") ? object.getString("wholesaleNumberTwo") : "";
                            String wholesaleNumberThree = object.has("wholesaleNumberThree") ? object.getString("wholesaleNumberThree") : "";
                            String proSpecifications = object.has("proSpecifications") ? object.getString("proSpecifications") : "";
                            String wholesalePriceOne = object.has("wholesalePriceOne") ? object.getString("wholesalePriceOne") : "";
                            String wholesalePriceTwo = object.has("wholesalePriceTwo") ? object.getString("wholesalePriceTwo") : "";
                            String wholesalePriceThree = object.has("wholesalePriceThree") ? object.getString("wholesalePriceThree") : "";
                            String address = object.has("address") ? object.getString("address") : "";
                            String originalPrice = object.has("originalPrice") ? object.getString("originalPrice") : "";
                            String freight = object.has("freight") ? object.getString("freight") : "";
                            String title = object.has("name") ? object.getString("name") : "";
                            String inventory = object.has("inventory") ? object.getString("inventory") : "";
                            String sales = object.has("sales") ? object.getString("sales") : "";

                            String measuringUnit = object.has("measuringUnit") ? object.getString("measuringUnit") : "";



                            commodity.setGuige(measuringUnit);
                            commodity.setSales(sales);
                            commodity.setProSpecifications(proSpecifications);
                            commodity.setPictureimage(pictureimage);
                            commodity.setImage(picture);
                            commodity.setWholesaleNumberOne(wholesaleNumberOne);
                            commodity.setWholesaleNumberTwo(wholesaleNumberTwo);
                            commodity.setWholesaleNumberThree(wholesaleNumberThree);
                            commodity.setWholesalePriceOne(wholesalePriceOne);
                            commodity.setWholesalePriceTwo(wholesalePriceTwo);
                            commodity.setWholesalePriceThree(wholesalePriceThree);
                            commodity.setAddress(address);
                            commodity.setOriginalPrice(originalPrice);
                            commodity.setFreight(freight);
                            commodity.setTitle(title);
                            commodity.setInventory(inventory);

//                            mGoods.add(commodity);
//                        }
                        handler.sendEmptyMessage(1);
                    }else {
                        mActivity.toastWk(jsonObject.getString(getResources().getString(R.string.errMsg)));
                    }
                } catch (Exception e) {
                    e.printStackTrace();

                }
            }
            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                ex.printStackTrace();
                mActivity.  dismissLoad();
            }
            @Override
            public void onCancelled(CancelledException cex) {

            }
            @Override
            public void onFinished() {

            }
        });
    }
    //添加购物车
    private void getADD(int number){
        mActivity. showLoad();
        RequestParams params = AllPublic.getParamsCart(mActivity, "/addCart", false);
        params.addParameter("merchantId",mActivity.getUser().getUid());
        params.addParameter("productId",goods_id);
        params.addParameter("number",number);
        Log.d("添加购物车", "getJSON: "+params);
        //请求
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override  //成功
            public void onSuccess(String result) {
                Log.d("添加购物车：", result);
                try {
                    JSONObject jsonObject= new JSONObject(result);
                    String reason = jsonObject.getString("code");
                    if (reason.equals("0")) {

                        mActivity.toastWk("添加成功");
                        sendBR();
                    }else {
                        mActivity.toastWk(jsonObject.getString(getResources().getString(R.string.errMsg)));
                    }
                } catch (Exception e) {
                    e.printStackTrace();

                }
                mActivity. dismissLoad();
            }
            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

                ex.printStackTrace();
                mActivity.  dismissLoad();
            }
            @Override
            public void onCancelled(CancelledException cex) {

                mActivity.  dismissLoad();
            }
            @Override
            public void onFinished() {

                mActivity.  dismissLoad();
            }
        });
    }
    public void sendBR(){
        activity. LogWk("购物车成功发送广播");
        Intent intent = new Intent();
        intent.setAction(Constants.MBroadcastReceiverCart);
        activity. sendBroadcast(intent);
    }
}
